// compile: g++ -o release_consume release_consume.cc -std=c++11
// run: ./release_consume
#include <atomic>
#include <chrono>
#include <iostream>
#include <thread>
using namespace std;

void Test1() {
  std::atomic<int*> ptr;
  int v;
  std::thread th1([&]() {
    int* p = new int(10);
    v = 20;
    std::this_thread::sleep_for(std::chrono::microseconds(100));
    // 执行store之前ptr值为默认初始化nullptr
    ptr.store(p, std::memory_order_release);
  });
  std::thread th2([&]() {
    int* p;

    while (!(p = ptr.load(std::memory_order_consume))) {
      cout << "线程th2 等一哈等一哈" << endl;
    }
    std::cout << "*p: " << *p << std::endl;
    std::cout << "v: " << v << std::endl;
  });
  th1.join();
  th2.join();
}
int main() {
  // Test1();
  std::atomic<int*> t;
  cout << (t == nullptr) << endl;
  return 0;
}
